package com.why.simpleboot.core.server.tomcat.mvc;

import com.why.simpleboot.core.core.ApplicationContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @program: why-simpleboot-framework
 * @description:
 * @author: @why
 * @create: 2021-07-03 20:05
 **/
public class DispatcherServlet extends HttpServlet {

    private static final ApplicationContext APPLICATION_CONTEXT = ApplicationContext.getAnnotationApplicationContext();
    private static final Logger log = LoggerFactory.getLogger(DispatcherServlet.class);

    /**
     * 执行请求
     */
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 设置请求编码方式
        req.setCharacterEncoding("UTF-8");
        //获取请求方法和请求路径
        String requestMethod = req.getMethod();
        String requestPath = req.getPathInfo();
        log.info("[DoodleConfig] {} {}", requestMethod, requestPath);
        if (requestPath.endsWith("/")) {
            requestPath = requestPath.substring(0, requestPath.length() - 1);
        }

        /**
         * 思路，也是和json那个一样操作就完了。先不弄这个了。
         */
        resp.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;

    }
}
